#include "StaticSprite.hpp"

/** 
* Create static sprite with provided texture.
*/
StaticSprite::StaticSprite(int spriteSheet, int spriteIndex, const sf::Texture& texture, int x, int y, int w, int h){
    type = BaseSprite::st_Static;
    sheet = spriteSheet;
    index = spriteIndex;
    drawSprite.setTexture(texture);
    drawSprite.setTextureRect(sf::IntRect(x, y, w, h));
    width = (float)w;
    height = (float)h;
    name = 0;
}

/** 
* Create static sprite without specified texture.
*/
StaticSprite::StaticSprite(int spriteSheet, int spriteIndex, int x, int y, int w, int h){
    sheet = spriteSheet;
    index = spriteIndex;
    drawSprite = sf::Sprite();
    drawSprite.setTextureRect(sf::IntRect(x, y, w, h));
    width = w;
    height = h;
    name = 0;
}

/** 
* Copy instance of static sprite.
*/
BaseSprite* StaticSprite::copy(){
    StaticSprite* sprite = new StaticSprite(sheet, index, *drawSprite.getTexture(),
            drawSprite.getTextureRect().left, drawSprite.getTextureRect().top,
            drawSprite.getTextureRect().width, drawSprite.getTextureRect().height);
    sprite->name = name;
    return sprite;
}

/** 
* Get SFML Sprite representation.
*/
sf::Sprite StaticSprite::getSprite(){
    return drawSprite;
}

/** 
* Draw this sprite to the target.
*/
void StaticSprite::draw(sf::RenderTarget& target, sf::RenderStates states) const {
    for(byte i = 0; i < transformationCounter; i++)
        transformations[i]->apply(states);

    target.draw(drawSprite, states);
}

/** 
* Doesn't delete anything. Name and texture references should be deleted
* by SpriteManager.
*/
StaticSprite::~StaticSprite(){
}